using GGPhysics;
using UnityEngine;

public class GGPCompositeLineCollider : GGPShape
{
	public override Shape shape
	{
		get
		{
			return CreateShapeForEngine();
		}
	}

	public override Shape CreateShapeForEngine()
	{
		CompositeLineShape compositeLineShape = new CompositeLineShape();
		InitializeWorldFromChildren(base.transform, compositeLineShape);
		return compositeLineShape;
	}

	private void OnDrawGizmos()
	{
		CompositeLineShape compositeLineShape = shape as CompositeLineShape;
		Color color = Gizmos.color;
		Gizmos.color = Color.blue;
		foreach (LineShape line in compositeLineShape.lines)
		{
			Vector3 from = base.transform.TransformDirection(line.point1) + base.transform.position;
			Vector3 to = base.transform.TransformDirection(line.point2) + base.transform.position;
			Gizmos.DrawLine(from, to);
		}
		Gizmos.color = color;
	}

	protected void InitializeWorldFromChildren(Transform transform, CompositeLineShape composite)
	{
		Transform transform2 = base.transform;
		foreach (Transform item in transform)
		{
			if (item.gameObject.activeSelf)
			{
				GGPLineCollider component = item.GetComponent<GGPLineCollider>();
				if (component != null)
				{
					LineShape line = component.line;
					LineShape lineShape = new LineShape();
					Vector3 vector = item.TransformPoint(line.point1);
					lineShape.point1 = transform2.InverseTransformDirection(vector - transform2.position);
					Vector3 vector2 = item.TransformPoint(line.point2);
					lineShape.point2 = transform2.InverseTransformDirection(vector2 - transform2.position);
					composite.lines.Add(lineShape);
				}
				InitializeWorldFromChildren(item, composite);
			}
		}
	}
}
